class Solution:
    def toHex(self, num: int) -> str:
        isDe = False
        if num==0:
            return '0'
        elif num<0:
            isDe = True
            num = abs(num)
        r = ""
        dic = "0123456789abcdef"
        while num:
            r = dic[num%16] + r
            num = num//16
        if isDe:
            r = '0'*(8-len(r)) + r
            r2 = ""
            for a in r:
                r2 += dic[15-dic.index(a)]
            isAdd = 1
            r = ""

            for i in range(7,-1,-1):
                r = dic[(dic.index(r2[i])+isAdd)%16] + r
                isAdd = (dic.index(r2[i])+isAdd)//16
            r = r[-8:]
            i = 0
            for i in range(8):
                if r[i] != '0':
                    break
            r = r[i:]
        return r



if __name__ == '__main__':
    so = Solution()
    num = -1
    r = so.toHex(num)
    print(r)
